<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
    <script src="../js/dayjs.min.js"></script>
</head>
<body>
    <div id="id" class="">
        <h2>#id模板</h2>
        <h1>时间格式化</h1>
        <p>当前时间戳：{{nowTime}}</p>
        <p>计算属性格式化：{{c_formatTime}}</p>
        <p>方法格式化：{{Fn_formatTime()}}</p>
        <!-- 过滤器格式化(无参) -->
        <p>过滤器格式化：{{nowTime | formatTime1}}</p>
        <!-- 过滤器格式化(传参) -->
        <p>过滤器格式化：{{nowTime | formatTime2('YYYY_MM_DD')}}</p>
        <hr>
        <h1>字符截取</h1>
        <p>{{str}} 截取后 {{str | mySlice}}</p>
    </div>
    <hr>
    <div id="id2" class="">
        <h2>#id2模板</h2>
        <p>{{str}} 截取后 {{str | mySlice}}</p>
    </div>
    <script>
        Vue.filter("mySlice",function(value){
            return value.slice(0,4)
        })
        new Vue({
            el: '#id',
            data: {
                nowTime:+Date.now(),
                str:'qwer1234'
            },
            computed:{
                c_formatTime(){
                    return dayjs(this.nowTime).format("YYYY_MM_DD")
                }
            },
            methods:{
                Fn_formatTime(){
                    return dayjs(this.nowTime).format("YYYY_MM_DD")
                }
            },
            filters:{
                formatTime1(value){
                    return dayjs(value).format("YYYY_MM_DD")
                },
                formatTime2(value,str = 'YYYY_MM_DD'){
                    return dayjs(value).format(str)
                }
            }
        });
        new Vue({
            el: '#id2',
            data:{
                str:'qwer123'
            }
        })
    </script>
</body>

</html>